package com.example.snailjob.controller;

import com.aizuda.snailjob.client.core.openapi.SnailRetryOpenApi;
import com.aizuda.snailjob.common.core.enums.RetryStatusEnum;
import com.aizuda.snailjob.model.response.RetryApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/open-api/retry")
@Tag(name = "RetryOpenApi", description = "通过OpenApi可以灵活的实现对Retry的操作")
public class OpenApiRetryController {

    @GetMapping("/query/{id}")
    public RetryApiResponse queryRetry(@PathVariable("id") Long id) {
        return SnailRetryOpenApi.queryTask(id).execute();
    }

    @GetMapping("/trigger/{id}")
    public Boolean triggerRetry(@PathVariable("id") Long id) {
        return SnailRetryOpenApi.triggerTask(id).execute();
    }

    @GetMapping("/status")
    public Boolean updateRetryStatus(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
        return SnailRetryOpenApi.updateTaskStatus(id)
                .setRetryStatus(RetryStatusEnum.getByStatus(status))
                .execute();
    }
}
